<?php
session_start();
error_reporting(E_ALL);
include_once 'include_classes.php';

//Connection bdd
$db=new DbConnection();
$db->OpenConnection();

$id=$_GET['id'];
$asso=$_GET['nom'];
$action=$_GET['action'];


if ($action==1){
        
        $sql='UPDATE MembreAsso SET Valide = 1 WHERE id='.$id.';';
        
        $query= new DbQuery($db,$sql);
        $query->SendQuery();
        $role=$_POST['role'];
        
        if (!empty($role)){
            $sql='INSERT INTO apourrole(membreasso, role) VALUES ('.$id.',\''.$role.'\');';
            
            $query= new DbQuery($db,$sql);
            $query->SendQuery();
        }
        
}
if ($action==0){
    $sql='DELETE FROM MembreAsso WHERE id=\''.$id.'\';';
    
    $query= new DbQuery($db,$sql);
    $query->SendQuery();

}
if ($action==2){
    $role=$_POST['role'];
    $personne=$_GET['id'];
    $sql='SELECT id FROM membreasso WHERE association=\''.$asso.'\' AND personne=\''.$id.'\' AND semestre=\''.GetSemester().'\';';
    $query= new DbQuery($db,$sql);
    $query->SendQuery();
    $result=$query->GetResult();
    $id=$result['id'];
    $sql='INSERT INTO apourrole(membreasso, role) VALUES (\''.$id.'\',\''.$role.'\');';
    $query= new DbQuery($db,$sql);
    $query->SendQuery();

}

    //Redirection
    echo '<meta http-equiv="Refresh" content="0;url=asso.php?nom='.$asso.'">';


?>
